﻿using InnoWeb.CEND.BL.Infrastructure;
using InnoWeb.CEND.Core.Model.News;
using InnoWeb.CEND.Data;
using InnoWeb.CEND.Data.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InnoWeb.CEND.BL.Service.News
{
    public class NewsContentService: IService<NewsContent>
    {
        private readonly GenericRepository<NewsContent> _newsContentRepository;
        private readonly IUnitOfWork _unitOfWork;

        public NewsContentService(IUnitOfWork unitOfWork, GenericRepository<NewsContent> newsContentRepository)
        {
            this._newsContentRepository = newsContentRepository;
            this._unitOfWork = unitOfWork;
        }

        public IQueryable<NewsContent> GetAllElements()
        {
            return _newsContentRepository.GetAll();
        }

        public NewsContent GetElementById(int id)
        {
            return _newsContentRepository.GetById(id);
        }

        public void CreateElement(NewsContent entity)
        {
            _newsContentRepository.Insert(entity);
        }

        public void UpdateElement(NewsContent entity)
        {
            _newsContentRepository.Update(entity);
        }

        public void DeleteElement(int id)
        {
            _newsContentRepository.Delete(id);
        }

        public void SaveChanges()
        {
            _unitOfWork.SaveChanges();
        }
    }
}
